package com.example.administrator.printoutindemo;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;


public class StoreOutStorageCheckList1Adapter extends BaseAdapter {

    private Context mContext = null;
    private List<OutStorageCheckList> li = null;
    private LayoutInflater mInflater = null;

    private class ViewHolder {
        TextView s_cl_ada1_txt_title;
        TextView tv_xiang_mu_bian_hao;
        TextView s_cl_ada1_txt_proid;
        TextView tv_ling_liao_dan_hao;
        TextView tv_shen_qing_ren;
        TextView tv_ling_liao_ren;
        Button s_cl_ada1_btn_check;
    }

    private ViewHolder holder = null;

    public StoreOutStorageCheckList1Adapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setList(List<OutStorageCheckList> li) {
        this.li = li;
        this.mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return li.size();
    }

    @Override
    public Object getItem(int position) {
        return li.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (null == convertView) {
            holder = new ViewHolder();

            convertView = mInflater.inflate(R.layout.store_adapter_outstoragechecklist_1, null);

            holder.s_cl_ada1_txt_title = (TextView) convertView.findViewById(R.id.s_cl_ada1_txt_title);
            holder.tv_xiang_mu_bian_hao = (TextView) convertView.findViewById(R.id.tv_xiang_mu_bian_hao);
            holder.tv_shen_qing_ren = (TextView) convertView.findViewById(R.id.tv_shen_qing_ren);
            holder.tv_ling_liao_ren = (TextView) convertView.findViewById(R.id.tv_ling_liao_ren);
            holder.s_cl_ada1_txt_proid = (TextView) convertView.findViewById(R.id.s_cl_ada1_txt_proid);
            holder.tv_ling_liao_dan_hao = (TextView) convertView.findViewById(R.id.tv_ling_liao_dan_hao);
            holder.s_cl_ada1_btn_check = (Button) convertView.findViewById(R.id.s_cl_ada1_btn_check);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (null != this.li) {

            OutStorageCheckList o = li.get(position);

//			holder.s_cl_ada1_txt_title.setText("项目名称："+o.get_projectname()+"\n项目编号："+o.get_proid());
            holder.s_cl_ada1_txt_title.setText(o.get_projectname());
            holder.tv_xiang_mu_bian_hao.setText(o.get_proid());
            holder.s_cl_ada1_txt_proid.setText(o.get_proid());
            holder.tv_ling_liao_dan_hao.setText(o.get＿out_storagelist_batchid());
            holder.tv_shen_qing_ren.setText(o.getApplyUserName());
            holder.tv_ling_liao_ren.setText(o.getReceiveUserName());

            holder.s_cl_ada1_btn_check.setOnClickListener(new s_cl_ada1_btn_check_click(o));
        }

        return convertView;
    }

    private class s_cl_ada1_btn_check_click implements View.OnClickListener {

        private OutStorageCheckList o;

        public s_cl_ada1_btn_check_click(OutStorageCheckList o) {
            this.o = o;
        }

        @Override
        public void onClick(View v) {

            Intent in = new Intent();
            Bundle bunl = new Bundle();
            String test = o.get＿out_storagelist_batchid();
            bunl.putString("outCheckProject", o.get＿out_storagelist_batchid());
            in.putExtras(bunl);
            in.setClass(mContext, StoreOutStorageCheckList2Activity.class);
            mContext.startActivity(in);
        }
    }

}